package com.hp.attendance.serlvet.history.OutGoing;

import com.hp.attendance.entity.History;
import com.hp.attendance.service.HistoryBysService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/updHistory")

public class HistoryUpdServlet extends HttpServlet {
    private HistoryBysService historyBysService = new HistoryBysService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String employee_number = req.getParameter("employee_number");
            String name = req.getParameter("name");
            String gender = req.getParameter("gender");
            String birthday = req.getParameter("birthday");
            String telephone = req.getParameter("telephone");
            String email = req.getParameter("email");
            String address = req.getParameter("address");
            //照片  null
            String education = req.getParameter("education");
//            String in_time = req.getParameter("in_time");
//            String out_time = req.getParameter("out_time");
//            String department_number = req.getParameter("department_number");
//            String position_number = req.getParameter("position_number");
//            String status = req.getParameter("status");
            String home = req.getParameter("home");
            String notes = req.getParameter("notes");

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date birth = format.parse(birthday.trim());

            History history = new History(null, Integer.parseInt(employee_number), name, gender, birth, telephone, email, address, null,
                    education, null, null,null ,null , null, home,notes);

            historyBysService.UpdateHistoryByNum(history);

            //跳转
            req.getRequestDispatcher("HistoryOutList").forward(req,resp);

        }

        catch (ParseException | SQLException | ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
